package com.game.chinesechess.piece.specific;


import com.game.chinesechess.piece.chess;
import com.game.chinesechess.util.Point;

public class carChess extends chess {
    public carChess(Color color, int x, int y) {
        this.color = color;
        this.point = new Point(x, y);
    }

    @Override
    public Boolean check(chess[][] map, int toX, int toY) {
        int xDistance = this.point.x - toX;
        int yDistance = this.point.y - toY;
        int count = 0;
        if (!((xDistance == 0 && yDistance != 0) || (xDistance != 0 && yDistance == 0)))
            return false;
        if (xDistance == 0) {
            int begin, end;
            if(yDistance<0){
                begin=this.point.y+1;
                end=toY;
            }else{
                begin=toY;
                end=this.point.y-1;
            }
            for (int i = begin; i < end; i++)
                if (map[this.point.x][i] != null)
                    return false;
        } else {
            int begin, end;
            if(xDistance<0){
                begin=this.point.x+1;
                end=toX;
            }else {
                begin=toX;
                end=this.point.x-1;
            }
            for (int i = begin; i < end; i++)
                if (map[i][this.point.y] != null)
                    return false;
        }
        return true;
    }

    @Override
    public String getName() {
        return "车";
    }
}
